package com.museum.controller;


import com.alibaba.fastjson.JSONObject;
import com.museum.base.BaseApiService;
import com.museum.base.BaseResponse;
import com.museum.controller.APi.RegisterControllerAPI;
import com.museum.entity.DO.Clue;
import com.museum.entity.DO.ClueRegister;
import com.museum.entity.DO.ColRegister;
import com.museum.entity.DTO.ColQuery;
import com.museum.entity.DTO.CommitCol;
import com.museum.entity.DTO.QueryCol;
import com.museum.service.impl.ClueServiceImpl;
import com.museum.service.impl.RegisterClueServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yznl
 * @since 2021-03-10
 */
@RestController
@RequestMapping("/register")
public class ColRegisterController extends BaseApiService<JSONObject> implements RegisterControllerAPI {
    @Autowired
    private RegisterClueServiceImpl clueService;

    @Override
    public BaseResponse<JSONObject> addClue(ColRegister clue, HttpServletRequest request) {
        int result = clueService.addClue(clue,request);
        if(result>0){
            return setResultSuccess("添加成功");
        }else{
            return setResultError("添加失败");
        }
    }

    @Override
    public BaseResponse<JSONObject> getAllColByPage(long current, long limit, ColQuery queryCol) {
        JSONObject json = clueService.getAllColByPage(current,limit,queryCol);
        return setResultSuccess(json);
    }

    @Override
    public BaseResponse<JSONObject> deleteColById(Integer id) {
        int result =  clueService.deleteColById(id);
        if(result>0){
            return setResultSuccess("删除成功");
        }else{
            return setResultError("删除失败");
        }
    }

    @Override
    public BaseResponse<JSONObject> commitCol(CommitCol commitCol, HttpServletRequest request) {
        int result =  clueService.commitCol(commitCol,request);
        if(result>0){
            return setResultSuccess("审核完成");
        }else{
            return setResultError("审核失败,系统错误");
        }
    }

    @Override
    public BaseResponse<JSONObject> clueInfo(Integer id) {
        JSONObject json =  clueService.clueInfo(id);
        return setResultSuccess(json);
    }

//    @Override
//    public BaseResponse<JSONObject> getAllColByPage2(long current, long limit, QueryCol queryCol) {
//        return null;
//    }
}
